<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla controller library
jimport('joomla.application.component.controller');
 
/**
 * General Controller of NGMenu component
 */
class NGMenuController extends JController
{
	
	var $imagepath;

	/**
	 * Constructor.
	 *
	 * @param	array	$config	An optional associative array of configuration settings.
	 *
	 * @return	NGMenuControllerNGMenus
	 * @see		JController
	 * @since	1.6
	 */
	public function __construct($config = array())
	{
		parent::__construct($config);
		
		$this->registerTask('changeweightlist', 'changeweightlist');

		// image paths for file uploads
		$arrows = NGMOD_PATH.DS.'mod_ngmenu'.DS.'images'.DS.'arrow';
		$backgrounds = NGMOD_PATH.DS.'mod_ngmenu'.DS.'images'.DS.'background';
		$icons = NGMOD_PATH.DS.'mod_ngmenu'.DS.'images'.DS.'icon';
		$separators = NGMOD_PATH.DS.'mod_ngmenu'.DS.'images'.DS.'separator';
		
		$this->imagepath = array(
			0 => $arrows,
			1 => $backgrounds,
			2 => $icons,
			3 => $separators
		);
	}

	/**
	 * display task
	 *
	 * @return void
	 */
	function display($cachable = false) 
	{
		// set default view if not set
		JRequest::setVar('view', JRequest::getCmd('view', 'ngmenus'));
		
		// call parent behavior
		parent::display($cachable);
	}

	function changeweightlist()
	{
		$value = JRequest::getString('ngvalue', '');
		
		$font_name = str_replace('+', ' ', $value);
		$font_name = explode('|', $font_name);
		
		$database =& JFactory::getDBO();
		$query = $database->getQuery(true);
		$query->select('variants');
		$query->from('#__ngmenu_fonts');
		$query->where("name='".$font_name[0]."'");
		$database->setQuery($query);
		$database->query();
		$variants = '';
		if($database->getNumRows()){
			$row = $database->loadAssoc();
			$variants = $row['variants'];
		}
		if(!empty($variants)){
			$variants_array = explode(',', $variants);
			$variants = '';
			$i = 0;
			foreach($variants_array as $variant){
				$variants .= ($i==0) ? '' : ';';
				switch ($variant){
					case '100':
						$variants .= '100:ultra-light';
						break;
					case '100italic':
						$variants .= '100italic:ultra-light-italic';
						break;
					case '200':
						$variants .= '200:light';
						break;
					case '200italic':
						$variants .= '200italic:light-italic';
						break;
					case '300':
						$variants .= '300:book';
						break;
					case '300italic':
						$variants .= '300italic:book-italic';
						break;
					case 'regular':
						$variants .= '400:normal';
						break;
					case 'italic':
						$variants .= '400italic:normal-italic';
						break;
					case '500':
						$variants .= '500:medium';
						break;
					case '500italic':
						$variants .= '500italic:medium-italic';
						break;
					case '600':
						$variants .= '600:semi-bold';
						break;
					case '600italic':
						$variants .= '600italic:semi-bold-italic';
						break;
					case '700':
						$variants .= '700:bold';
						break;
					case '700italic':
						$variants .= '700italic:bold-italic';
						break;
					case '800':
						$variants .= '800:extra-bold';
						break;
					case '800italic':
						$variants .= '800italic:extra-bold-italic';
						break;
					case '900':
						$variants .= '900:ultra-bold';
						break;
					case '900italic':
						$variants .= '900italic:ultra-bold-italic';
						break;
				}
				$i+=1;
			}
		}else{
			$variants .= 'normal:normal;bold:bold;bolder:bolder;lighter:lighter';
		}
		
		echo $variants;
	}
}
